<!--
  用户管理-企业用户-身份认证页面（企业未认证时，只展示这个页面）
 -->
<template>
  <div v-loading="pageLoading" class="app-container">
    <!-- 新建-步骤一，填写用户信息 -->
    <div v-if="nextStep === 1">
      <div
        v-if="dataObj.remark && dataObj.authorizedStatus === 'reject'"
        class="auth-status"
      >
        审核不通过：{{ dataObj.remark }}
      </div>
      <p v-if="authorizedStatus == 'authorized'">填写用户信息(您已认证)</p>
      <p v-else-if="authorizedStatus == 'authorizeding'">
        填写用户信息(未完成认证/审核中)
      </p>
      <p v-else>填写用户信息(未完成认证)</p>
      <el-form
        ref="userForm"
        :model="userForm"
        :rules="rules"
        label-width="80px"
        :validate-on-rule-change="false"
      >
        <el-form-item label="姓名" prop="applyUserName">
          <el-input
            v-model="userForm.applyUserName"
            v-maxLenght="50"
            :disabled="isAuth"
            style="width: 50%"
            placeholder="请输入姓名"
          />
        </el-form-item>
        <el-form-item label="企业/单位名称" prop="companyName">
          <el-input
            v-model="userForm.companyName"
            v-maxLenght="64"
            style="width: 50%"
            :disabled="isAuth"
            placeholder="请输入企业/单位名称"
          />
        </el-form-item>
        <el-form-item label="手机号" prop="phoneNumber">
          <el-input
            v-model="userForm.phoneNumber"
            v-maxLenght="20"
            style="width: 50%"
            :disabled="companyLoginPhone !== '' || isAuth"
            placeholder="请输入手机号"
          />
        </el-form-item>
        <el-form-item label="部门" prop="dept">
          <el-input
            v-model="userForm.dept"
            v-maxLenght="50"
            style="width: 50%"
            :disabled="isAuth"
            placeholder="请输入部门"
          />
        </el-form-item>
        <el-form-item label="职位" prop="job">
          <el-input
            v-model="userForm.job"
            v-maxLenght="32"
            style="width: 50%"
            :disabled="isAuth"
            placeholder="请输入职位"
          />
        </el-form-item>
        <el-form-item label="座机号">
          <el-input
            v-model="userForm.tel"
            v-maxLenght="20"
            maxlenght="12"
            :disabled="isAuth"
            style="width: 50%"
            placeholder="请输入座机号"
          />
        </el-form-item>
        <el-form-item label="邮箱号" prop="email">
          <el-input
            v-model="userForm.email"
            v-maxLenght="50"
            style="width: 50%"
            :disabled="isAuth"
            placeholder="请输入邮箱号"
          />
        </el-form-item>
        <el-form-item v-if="isAdmin" label="账户类型">
          <el-select disabled value="1">
            <el-option value="1" label="企业管理员">企业管理员</el-option>
          </el-select>
        </el-form-item>
        <div v-if="unrealFlag != 1">
          <el-form-item label="身份证信息" required />
          <el-form-item label="身份证号码" required prop="cardNo">
            <el-input
              v-model="userForm.cardNo"
              v-maxLenght="18"
              style="width: 50%"
              :disabled="isAuth"
              placeholder="身份证号码"
            />
          </el-form-item>

          <el-form-item
            label="身份证正面"
            prop="authenticationFrontPictureUrl"
            required
          >
            <div style="padding-left: 100px">
              <imageUpload
                v-if="!isAuth"
                v-model="userForm.authenticationFrontPictureUrl"
                :show-tip="false"
              />
              <img
                v-else
                :src="userForm.authenticationFrontPictureUrl"
                style="
                  display: block;
                  width: 148px;
                  height: 148px;
                  border-radius: 8px;
                "
                alt=""
              >
              <!-- <div class="tips">请上传身份证正面照片</div> -->
            </div>
          </el-form-item>

          <el-form-item
            label="身份证反面"
            prop="authenticationBackPictureUrl"
            required
          >
            <div style="padding-left: 100px">
              <imageUpload
                v-if="!isAuth"
                v-model="userForm.authenticationBackPictureUrl"
                :show-tip="false"
              />
              <img
                v-else
                :src="userForm.authenticationBackPictureUrl"
                style="
                  display: block;
                  width: 148px;
                  height: 148px;
                  border-radius: 8px;
                "
                alt=""
              >
              <!-- <div class="tips">请上传身份证正面照片</div> -->
            </div>
          </el-form-item>
          <el-form-item label="在职证明" prop="onjobUrl" required>
            <div style="padding-left: 100px">
              <imageUpload
                v-if="!isAuth"
                v-model="userForm.onjobUrl"
                :show-tip="false"
              />
              <img
                v-else
                :src="userForm.onjobUrl"
                style="
                  display: block;
                  width: 148px;
                  height: 148px;
                  border-radius: 8px;
                "
                alt=""
              >
              <!-- <div class="tips" style="width: 100%; margin: 0 0 52px;   justify-content: flex-start;">请上传在职证明照片（工卡、飞书在线等在职证明）</div> -->
            </div>
          </el-form-item>
        </div>
      </el-form>
      <el-row type="flex">
        <el-button type="primary" @click="submitUserForm">下一步</el-button>
      </el-row>
    </div>

    <!-- 阿里认证弹窗 -->
    <div v-if="showAuthentication" class="showAuthentication">
      <div class="showAuthenticationBox">
        <div class="title">实名认证</div>
        <div v-loading="showLoading" class="content">
          {{ authenticationTitle }}
        </div>
        <div class="btns">
          <div class="cancel" @click="showAuthentication = !showAuthentication">
            取消
          </div>
          <div
            class="submit"
            @click="
              () => {
                nextStep = 2;
                showAuthentication = false;
              }
            "
          >
            确定
          </div>
        </div>
      </div>
    </div>
    <!-- 新建-步骤二，填写企业信息 -->
    <div v-if="nextStep == 2">
      <p>填写企业信息</p>
      <el-form
        ref="companyForm"
        :model="companyForm"
        :rules="rules"
        label-width="200px"
      >
        <el-form-item label="统一社会信用代码" prop="creditCode">
          <el-input
            v-model="companyForm.creditCode"
            v-maxLenght="64"
            style="width: 50%"
            :disabled="isAuth"
            placeholder="请输入统一社会信用代码"
          />
        </el-form-item>
        <el-form-item label="营业执照图片" prop="businessLicense">
          <imageUpload v-if="!isAuth" v-model="companyForm.businessLicense" />
          <img
            v-else
            :src="companyForm.businessLicense"
            style="
              display: block;
              width: 148px;
              height: 148px;
              border-radius: 8px;
            "
            alt=""
          >
        </el-form-item>
        <el-form-item label="行业类型" prop="industry">
          <el-cascader
            v-model="companyForm.industry"
            :options="businessAreaData"
            :show-all-levels="false"
            :disabled="isAuth"
            @change="businessAreaChange"
          />
        </el-form-item>
        <el-form-item label="邮政编码" prop="postCode">
          <el-input
            v-model="companyForm.postCode"
            v-maxLenght="10"
            style="width: 50%"
            :disabled="isAuth"
            placeholder="请输入邮政编码"
          />
        </el-form-item>
        <el-form-item label="经营状态" prop="businessStatus">
          <el-radio-group
            v-model="companyForm.businessStatus"
            :disabled="isAuth"
          >
            <el-radio
              v-for="dict in getDictDatas(DICT_TYPE.COMPANY_BUSINESS_STATUS)"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="注册资本（万元）" prop="registeredCapital">
          <el-input
            v-model="companyForm.registeredCapital"
            v-maxLenght="64"
            style="width: 50%"
            :disabled="isAuth"
            type="number"
            min="0"
            placeholder="请输入注册资本"
          />
        </el-form-item>
        <el-form-item label="成立日期" prop="establishDate">
          <el-date-picker
            v-model="companyForm.establishDate"
            clearable
            type="date"
            :disabled="isAuth"
            value-format="yyyy-MM-dd"
            placeholder="选择成立日期"
            :picker-options="pickerOptionStop"
          />
        </el-form-item>
        <el-form-item label="法定代表人" prop="legalPerson">
          <el-input
            v-model="companyForm.legalPerson"
            v-maxLenght="50"
            style="width: 50%"
            :disabled="isAuth"
            placeholder="请输入法定代表人"
          />
        </el-form-item>
        <el-form-item label="法定代表人身份证正面">
          <!-- <imageUpload
            v-model="companyForm.legalPersonFrontPictureUrl"
          /> -->
          <imageUpload
            v-if="!isAuth"
            v-model="companyForm.legalPersonFrontPictureUrl"
            :show-tip="false"
          />
          <img
            v-else
            v-imgError
            :src="companyForm.legalPersonFrontPictureUrl"
            style="
              display: block;
              width: 148px;
              height: 148px;
              border-radius: 8px;
            "
            alt=""
          >
        </el-form-item>
        <el-form-item label="法定代表人身份证反面">
          <imageUpload
            v-if="!isAuth"
            v-model="companyForm.legalPersonBackPictureUrl"
            :show-tip="false"
          />
          <img
            v-else
            v-imgError
            :src="companyForm.legalPersonBackPictureUrl"
            style="
              display: block;
              width: 148px;
              height: 148px;
              border-radius: 8px;
            "
            alt=""
          >
        </el-form-item>
        <el-form-item label="子企业关系证明图片">
          <imageUpload
            v-if="!isAuth"
            v-model="companyForm.subCompanyRelationshipCertificatePicture"
            :show-tip="false"
          />
          <img
            v-else
            v-imgError
            :src="companyForm.subCompanyRelationshipCertificatePicture"
            style="
              display: block;
              width: 148px;
              height: 148px;
              border-radius: 8px;
            "
            alt=""
          >
          <!-- <el-button v-if="!isAuth" type="text" @click="downloadFile">下载模版</el-button> -->
        </el-form-item>
        <el-form-item label="企业规模" prop="scale">
          <el-select
            v-model="companyForm.scale"
            :disabled="isAuth"
            placeholder="请输入企业规模"
          >
            <el-option
              v-for="dict in getDictDatas(DICT_TYPE.ENTERPRISE_SCALE)"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="企业类型" prop="companyType">
          <el-select
            v-model="companyForm.companyType"
            :disabled="isAuth"
            placeholder="请选择企业状态"
          >
            <el-option
              v-for="dict in getDictDatas(DICT_TYPE.COMPANY_TYPE)"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="注册地址" required prop="provinceAndCity">
          <el-cascader
            v-model="companyForm.provinceAndCity"
            v-maxLenght="64"
            :options="provinceAndCityData"
            :disabled="isAuth"
            placeholder="请选择注册地址"
            style="width: 50%"
            @change="handleChangeAddress"
          />
        </el-form-item>
        <el-form-item label="详细地址" prop="registeredAddress">
          <el-input
            v-model="companyForm.registeredAddress"
            v-maxLenght="64"
            :disabled="isAuth"
            style="width: 50%"
            placeholder="请输入详细地址"
          />
        </el-form-item>
        <el-form-item label="经营范围" prop="businessScope">
          <el-input
            v-model="companyForm.businessScope"
            v-maxLenght="1024"
            :disabled="isAuth"
            type="textarea"
            style="width: 50%"
            placeholder="请输入经营范围"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="backToUserForm">上一步</el-button>
        <el-button
          v-if="!isAuth"
          type="primary"
          @click="submitCompanyForm"
        >提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getCompanyByLoginUser } from '@/api/company-admin-api/hireManage/index.js'
import { getUserConfig } from '@/api/company-admin-api/userManage'
import router from '../../../router'
import { getIsAdmin } from '@/api/company-admin-api/hireManage/index.js'
import {
  isCompanyAuthStatus,
  getCompanyData
  //   isRealName
} from '@/api/company-admin-api/userManage/index.js'
import { companyAuth } from '@/api/company-admin-api/userManage/index.js'
import ImageUpload from '@/components/ImageUpload'
import businessAreaData from '@/utils/businessAreaData.js'
import { getPath } from '@/utils/ruoyi'
import Cookies from 'js-cookie'
import moment from 'moment'
import { getToken } from '@/utils/auth'
import {
  provinceAndCityData,
  getProvinceAndCityDataLabel,
  getProvinceAndCityDataValue
} from '@/utils/frontDataDict.js'
export default {
  name: 'Company',
  components: {
    ImageUpload
  },
  data() {
    const validatePhone = (rule, value, callback) => {
      const phoneReg = /^[1][0-9]{1,}$/
      if (value === '') {
        return callback(new Error('手机号不能为空'))
      } else {
        if (phoneReg.test(value)) {
          return callback()
        } else {
          return callback(new Error('格式有误'))
        }
      }
    }
    const validataEmail = (rule, value, callback) => {
      const emailReg =
        /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
      if (value === '') {
        return callback(new Error('邮箱不可为空'))
      } else {
        if (emailReg.test(value)) {
          return callback()
        } else {
          return callback(new Error('格式有误'))
        }
      }
    }
    return {
      pickerOptionStop: {
        disabledDate: (time) => {
          const newTime = new Date()
          return time.getTime() >= newTime
        }
      },
      isAdmin: false,
      loading2: false,
      loading1: false,
      showLoading: false,
      provinceAndCityData,
      showAuthentication: false,
      pageLoading: true,
      authorizedStatus: '',
      authenticationTitle: '',
      action: process.env.VUE_APP_BASE_API + 'admin-api/infra/file/upload', // 请求地址
      headers: { Authorization: 'Bearer ' + getToken() }, // 设置上传的请求头部
      nextStep: 1, // 第一步
      // 企业行业类型数据，二级联动
      businessAreaData: businessAreaData,
      // 遮罩层
      loading: true,
      dataObj: {},
      // 用户信息表
      userForm: {
        applyUserName: '', // 企业申请人姓名
        dept: '', // 部门
        job: '', // 职位
        tel: '', // 电话
        email: '', // 邮箱
        companyName: '', // 公司名字
        phoneNumber: '', // 手机号
        authenticationFrontPictureUrl: '', // 身份证正面
        authenticationBackPictureUrl: '', // 身份证反面
        cardNo: '', // 手身份证号码
        onjobUrl: '' // 在职证明
      },
      // 企业信息表
      companyForm: {
        creditCode: '', // 统一信用代码
        businessLicense: '', // 营业执照
        industry: [], // 行业类型
        postCode: '', // 邮政编码
        businessStatus: 'renew', // 经营状态
        registeredCapital: '', // 注册资本
        establishDate: '', // 成立日期
        legalPerson: '', // 法人
        legalPersonFrontPictureUrl: '', // 法人身份证正面
        legalPersonBackPictureUrl: '', // 法人身份证反面
        subCompanyRelationshipCertificatePicture: '', // 子母企业关系证明
        scale: '', // 企业规模
        companyType: '', // 企业类型
        status: '-1', // -2 禁用 -1 启用 写死是-1
        provinceAndCity: '', // 注册地址
        registeredAddress: '', // 详细地址
        businessScope: '', // 经营范围
        registerIp: '127.0.0.1' // 注册ip地址,写死，冗余字段
      },
      // 表单校验
      rules: {
        applyUserName: [
          {
            required: true,
            message: '企业申请人姓名不能为空',
            trigger: 'blur'
          }
        ],
        phoneNumber: [
          { required: true, validator: validatePhone, trigger: 'blur' }
        ],
        // tel: [{ required: true, message: '座机号不能为空', trigger: 'blur' }],
        email: [{ required: true, validator: validataEmail, trigger: 'blur' }],
        dept: [{ required: true, message: '部门不能为空', trigger: 'blur' }],
        job: [{ required: true, message: '职位不能为空', trigger: 'blur' }],
        companyName: [
          { required: true, message: '企业名称不能为空', trigger: 'blur' }
        ],
        creditCode: [
          {
            required: true,
            message: '统一社会信用代码不能为空',
            trigger: 'blur'
          }
        ],
        businessLicense: [
          {
            required: true,
            message: '营业执照图片不能为空',
            trigger: 'blur'
          }
        ],
        industry: [
          {
            type: 'array',
            required: true,
            message: '行业类型不能为空',
            trigger: 'change'
          }
        ],
        postCode: [
          { required: false, message: '邮政编码不能为空', trigger: 'blur' }
        ],
        businessStatus: [
          { required: true, message: '经营状态不能为空', trigger: 'blur' }
        ],
        registeredCapital: [
          { required: true, message: '注册资本不能为空', trigger: 'blur' }
        ],
        establishDate: [
          { required: true, message: '成立日期不能为空', trigger: 'blur' }
        ],
        legalPerson: [
          { required: true, message: '法定代表人不能为空', trigger: 'blur' }
        ],
        scale: [
          { required: true, message: '企业规模不能为空', trigger: 'blur' }
        ],
        companyType: [
          { required: true, message: '企业类型不能为空', trigger: 'change' }
        ],
        provinceAndCity: [
          { required: true, message: '注册地址不能为空', trigger: 'blur' }
        ],
        registeredAddress: [
          { required: true, message: '详细地址不能为空', trigger: 'blur' }
        ],
        businessScope: [
          { required: true, message: '经营范围不能为空', trigger: 'blur' }
        ],
        subCompanyRelationshipCertificatePicture: [
          {
            required: false,
            message: '子企业关系证明图片不能为空',
            trigger: 'blur'
          }
        ]
      },
      isAuth: false,
      unrealFlag: false,
      companyLoginPhone: '' // 用户登录的手机号，自动回填，禁止编辑
    }
  },
  watch: {
    'companyForm.registeredCapital'(newValue) {
      if (newValue < 0) {
        this.companyForm.registeredCapital = 0
      }
    },
    userForm: {
      handler: function(newValue, oldValue) {
        let isEmpty = true
        Object.keys(newValue).map((item) => {
          if (item !== 'phoneNumber' && newValue[item] !== '') {
            isEmpty = false
          }
        })
        if (!isEmpty) {
          const cacheData = JSON.stringify({
            phoneNumber: newValue.phoneNumber,
            data: newValue
          })
          localStorage.setItem('companyCacheUserForm', cacheData)
        }
      },
      deep: true
    },
    companyForm: {
      handler: function(newValue, oldValue) {
        let isEmpty = true
        Object.keys(newValue).map((item) => {
          if (newValue[item] !== '') {
            isEmpty = false
          }
        })
        if (!isEmpty) {
          const cacheData = JSON.stringify({
            phoneNumber: this.userForm.phoneNumber,
            data: newValue
          })
          localStorage.setItem('companyCacheCompanyForm', cacheData)
        }
      },
      deep: true
    }
  },
  created() {
    this.companyLoginPhone = localStorage.getItem('companyLoginPhone') || ''
    if (this.companyLoginPhone) {
      this.userForm.phoneNumber = this.companyLoginPhone + ''
    }
    this.init()
  },
  methods: {
    init() {
      this.checkAuth()
    },
    handleChangeAddress(e) {},
    checkAuth() {
      const tenantId = Cookies.get('tenantId')
      // 是否已认证
      isCompanyAuthStatus({ tenantId: tenantId })
        .then(async(res) => {
          if (res.code === 0 && res.data) {
            this.isAuth = true
            this.pageLoading = false
          } else {
            this.pageLoading = false
          }
          getCompanyByLoginUser().then((res) => {
            if (res.code === 0 && res.data) {
              this.$store.dispatch('updateCompanyInfo', res.data)
              if (this.isAuth) {
                // 已认证,直接更新路由, 第二个参数传true，表示前端隐藏企业认证页面
                this.$store
                  .dispatch('GenerateRoutes', true)
                  .then((accessRoutes) => {
                    router.addRoutes(accessRoutes) // 动态添加可访问路由表
                    if (res.data?.authorizedStatus === 'authorized') {
                      this.$router.push({
                        path: '/analytics/analytics',
                        replace: true
                      })
                    } else if (res.data?.authorizedStatus === 'changeing') {
                      this.$router.push({
                        path: '/userManage/personalCenter/accountChange',
                        replace: true
                      })
                    }
                  })
              }
            }
          })
          // 是否为企业管理员
          getIsAdmin().then((res) => {
            if (res.code === 0 && res.data) {
              this.isAdmin = true
            }
          })
          getUserConfig().then((res) => {
            if (res.code === 0 && res.data) {
              this.$store.dispatch('updateUserInfo', res.data)
              this.unrealFlag = res.data.unrealFlag
              if (Number(res.data.unrealFlag) !== 1) {
                // 非白名单企业则走三要素认证
                this.rules = {
                  ...this.rules,
                  cardNo: [
                    {
                      required: true,
                      message: '身份证号码不能为空',
                      trigger: 'change'
                    },
                    {
                      required: true,
                      message: '身份证号码不能为空',
                      trigger: 'blur'
                    }
                  ],
                  authenticationFrontPictureUrl: [
                    {
                      required: true,
                      message: '请选择身份证正面',
                      trigger: 'blur'
                    }
                  ],
                  authenticationBackPictureUrl: [
                    {
                      required: true,
                      message: '请选择身份证反面面',
                      trigger: 'blur'
                    }
                  ],
                  onjobUrl: [
                    {
                      required: true,
                      message: '请上传在职证明照片（工卡、飞书在线等在职证明）',
                      trigger: 'blur'
                    }
                  ]
                }
                this.$refs.userForm.clearValidate()
              }
            }
          })
          getCompanyData().then((res) => {
            const objData = res.code === 0 && res.data // 接口有数据就拿接口的，否则拿缓存
            // const objData = res.code === 0 && res.data
            this.$refs['userForm'] && this.$refs['userForm'].clearValidate()
            if (objData) {
              localStorage.setItem('companyLoginPhone', res.data.phoneNumber)
              const { establishDate, industry } = objData
              this.dataObj = objData
              this.authorizedStatus = objData.authorizedStatus
              if (this.authorizedStatus === 'authorizeding') {
                this.isAuth = true
              }
              try {
                objData.industry = JSON.parse(industry)
              } catch (error) {
                objData.industry = []
              }
              objData.establishDate =
                moment(establishDate).format('yyyy-MM-DD')
              for (const key in objData) {
                if (Object.hasOwnProperty.call(this.userForm, key)) {
                  this.userForm[key] = objData[key]
                }
                if (Object.hasOwnProperty.call(this.companyForm, key)) {
                  this.companyForm[key] = objData[key]
                }
              }

              try {
                objData &&
                  objData.province &&
                  (this.companyForm.provinceAndCity =
                    getProvinceAndCityDataValue(
                      objData.province + objData.city
                    ) || '')
              } catch {
                () => {}
              }
            } else {
              let companyUserData = null
              try {
                companyUserData = localStorage.getItem('companyCacheUserForm')
                companyUserData = companyUserData && JSON.parse(companyUserData)
                if (
                  companyUserData &&
                  Number(companyUserData.phoneNumber) ===
                    Number(this.companyLoginPhone)
                ) {
                  companyUserData = companyUserData.data
                  Object.assign(this.userForm, companyUserData)
                }
              } catch (error) {
                console.error('企业用户缓存信息无效>>>', error)
              }
              let companyData = null
              try {
                companyData = localStorage.getItem('companyCacheCompanyForm')
                companyData = companyData && JSON.parse(companyData)
                if (
                  companyData &&
                  Number(companyData.phoneNumber) ===
                    Number(this.companyLoginPhone)
                ) {
                  companyData = companyData.data
                  Object.assign(this.companyForm, companyData)
                }
              } catch (error) {
                console.error('企业缓存公司信息无效>>>', error)
              }
            }
          })
        })
        .catch(() => {
          this.pageLoading = false
        })
    },
    // 下载子企业关系证明模版
    downloadFile() {
      window.open('https://www.baidu.com/aaa/p1.pgn')
    },
    // 新建-提交用户信息
    submitUserForm() {
      this.$refs.userForm.validate((boo) => {
        if (boo) {
          this.nextStep = 2
          //   if (this.isAuth || Number(this.unrealFlag) === 1) {
          //     this.nextStep = 2
          //     return
          //   }
          //   this.showLoading = true
          //   this.showAuthentication = true
          //   isRealName({
          //     cardNo: this.userForm.cardNo,
          //     phone: this.userForm.phoneNumber,
          //     userName: this.userForm.applyUserName
          //     // phone: '18318355344',//this.userForm.phoneNumber,
          //     // userName: '余仲锋'//this.userForm.applyUserName
          //   })
          //     .then((res) => {
          //       this.showLoading = false
          //       const { code, message } = res.data
          //       if (Number(code) === 1) {
          //         this.authenticationTitle = '认证成功'
          //       } else {
          //         this.authenticationTitle = message || '认证失败'
          //       }
          //     })
          //     .catch(() => {
          //       this.authenticationTitle = '认证失败'
          //       this.showLoading = false
          //     })
          // this.nextStep = 2
        }
      })
    },
    // 企业行业类型修改
    businessAreaChange(value) {
      this.companyForm.industryType = value
    },
    backToUserForm() {
      this.nextStep = 1
    },
    // 新建-提交企业信息
    submitCompanyForm() {
      if (this.authorizedStatus === 'authorizeding') {
        this.$message.error('认证中，请等待审核')
        return
      }
      this.$refs.companyForm.validate((boo) => {
        if (boo) {
          this.$confirm(
            '为加快审核时间，请确认提交信息真实有效,认证成功后，该账号将升级为企业管理员账号',
            '提示',
            {
              confirmButtonText: '确 认',
              cancelButtonText: '取 消'
            }
          )
            .then(() => {
              const params = Object.assign({}, this.userForm, this.companyForm)
              params.industry = JSON.stringify(params.industry)
              params.industryType = params.industry
              params.city = getProvinceAndCityDataLabel(params.provinceAndCity)
              params.province = getProvinceAndCityDataLabel(
                params.provinceAndCity,
                3
              )
              companyAuth(params).then((res) => {
                if (res.code === 0) {
                  this.nextStep = 1
                  this.authorizedStatus = 'authorizeding'
                  this.dataObj.authorizedStatus = 'authorizeding'
                  this.isAuth = true
                  params.authorizedStatus = 'authorizeding'
                  // localStorage.setItem('companyData', JSON.stringify(params))
                  this.$message.success('提交成功，请等待平台审核')
                } else if (res.code === 403) {
                  /**
                   * 注意！由于企业提交认证后，页面并不会跳转，这里再次提交后，需要判断是否已经通过，通过要手动退出登录，并且提示用户认证成功重新登录
                   * 后端返回“用户不存在”表示运营那边已经通过审核，角色已经变了
                   */
                  this.$store.dispatch('LogOut').then(() => {
                    this.$message.success('已审核通过，请重新登录')
                    const loginType =
                      localStorage.getItem('loginType') || 'company'
                    if (loginType === 'admin') {
                      location.href = getPath('/#/adminLogin')
                    } else {
                      location.href = getPath('/#/login')
                    }
                  })
                }
              })
            })
            .catch(() => console.info('操作取消'))
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.demo-image__preview {
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  display: flex;
  position: relative;

  .el-image {
    width: 100%;
    height: 100%;
  }
}

.close {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  width: 20px;
  height: 20px;
  right: 0;
  top: 20px;
  border-radius: 20px;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
}

.avatar-uploader {
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  display: flex;
  border-radius: 9px;
  border: 2px dashed #3d6cb0;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 38px;
  color: #3d6cb0;
  font-weight: 600;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.tips {
  display: flex;
  // justify-content: center;
  align-items: center;
  position: relative;
  font-size: 16px;
  height: 30px;
  margin-top: 15px;
  width: 100%;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #37383d;
  line-height: 28px;
}

.content-title {
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #37383d;
  line-height: 25px;
  margin-bottom: 16px;
  &::before {
    content: "*";
    color: #f56c6c;
    margin-right: 4px;
  }
}
::v-deep .el-form-item__label {
  width: 180px !important;
}

.showAuthentication {
  position: fixed;
  z-index: 2014;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  .showAuthenticationBox {
    width: 360px;
    height: 241px;
    padding: 66px 30px 90px;
    border-radius: 12px;
    background: #fff;
    position: relative;
    .content {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 15px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #37383d;
      line-height: 21px;
    }
    .content2 {
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 15px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #37383d;
      line-height: 21px;
    }
    .title {
      position: absolute;
      width: 100%;
      left: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 18px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #37383d;
      line-height: 25px;
      top: 25px;
    }
    .title2 {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #37383d;
      line-height: 20px;
      margin-bottom: 12px;
    }
    .btns {
      width: 100%;
      height: 40px;
      position: absolute;
      bottom: 40px;
      left: 0;
      display: flex;
      justify-content: space-between;
      padding: 0 40px;
      & > div {
        width: 130px;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 14px;
        font-size: 14px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #4677b9;
        border: 1px solid #4677b9;
        border-radius: 2px;
        cursor: pointer;
        &.submit {
          background: #4677b9;
          color: #fff;
          border: none;
        }
      }
    }
  }
}
.auth-status {
  display: inline-flex;
  padding: 10px;
  background: rgba(254, 78, 61, 0.1);
  border-radius: 4px;
  border: 1px solid #fe4e3d;
  position: relative;
  font-size: 15px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #fe4e3d;
  line-height: 1;
  margin-bottom: 15px;
  // img{
  //   position: absolute;
  //   left: 8px;
  //   width: 15px;
  //   height: 18px;
  //   top: 50%;
  //   transform: translateY(-50%);
  // }
}
</style>
